/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ProcessMappingWindow.java
 *
 * Created on 21.10.2009, 10:12:21
 */

package at.nhmwien.schema_mapping_tool;

import javax.swing.*;
import java.util.*;
import java.nio.charset.*;

import at.nhmwien.schema_mapping_tool.fileProcessors.*;
import at.nhmwien.schema_mapping_tool.mappingProcess.*;

/**
 *
 * @author wkoller
 */
public class ProcessMappingWindow extends javax.swing.JFrame {
    MappingTask task;
    MappingProcess mp;
    DataSourceOptionsPanel inputOptionsPanel = null;
    DataSourceOptionsPanel outputOptionsPanel = null;
    //ChangeFieldOrderWindow cfoWindow = new ChangeFieldOrderWindow();

    // TODO: Improve mappingTask
    class MappingTask extends SwingWorker<Void, Void> {
        public Void doInBackground() {
            try {
                // Reset progress-Bar
                progressBar.setValue(0);
                progressBarLabel.setText("Creating File Processors");

                FileProcessor ifp = ProcessorHandler.self().getProcessorForType((String) inputFileFormatComboBox.getSelectedItem());
                FileProcessor ofp = ProcessorHandler.self().getProcessorForType((String) outputFileFormatComboBox.getSelectedItem());

                progressBar.setValue(10);
                progressBarLabel.setText("Preparing & Initializing File Processors");

                mp.setProcessor( ifp , ofp );

                mp.setInputFile( inputOptionsPanel.getFileName() , (Charset) ifEncodingComboBox.getSelectedItem() );
                mp.setOutputFile( outputOptionsPanel.getFileName() , (Charset) ofEncodingComboBox.getSelectedItem() );

    /*            if( ifp.getClass().getName().contains( "JDBCProcessor" ) ) {
    //                mp.setInputFile( jdbcURLTextField.getText() + dbnameTextField.getText() + "?user=" + usernameTextField.getText() + "&password=" + String.copyValueOf(passwordField.getPassword()) + "&" + tableField.getText() , (Charset) ifEncodingComboBox.getSelectedItem() );
                }
                else {
    //                mp.setInputFile( inputFileName.getText() , (Charset) ifEncodingComboBox.getSelectedItem() );
                }

                if( ofp.getClass().getName().contains( "JDBCProcessor" ) ) {
    //                mp.setOutputFile( jdbcURLTextField.getText() + dbnameTextField.getText() + "?user=" + usernameTextField.getText() + "&password=" + String.copyValueOf(passwordField.getPassword()) + "&" + tableField.getText() , (Charset) ifEncodingComboBox.getSelectedItem() );
                }
                else {
    //                mp.setOutputFile( outputFileName.getText() , (Charset) ofEncodingComboBox.getSelectedItem() );
                }*/

                /*try {
                    ifp.setFile(new File(inputFileName.getText()));
                    ifp.setEncoding( (Charset) ifEncodingComboBox.getSelectedItem());
                    ifp.prepareFileRead();

                    ofp.setFile(new File(outputFileName.getText()));
                    ofp.setEncoding( (Charset) ofEncodingComboBox.getSelectedItem());
                    ofp.prepareFileWrite();
                } catch (Exception e) {
                    e.printStackTrace();
                    //JOptionPane.showMessageDialog(this, "An error occured while trying to process the files:\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
                }*/

                progressBar.setValue(15);
                progressBarLabel.setText("Converting Mappings-Hash & Preparing Processors");

                try {
                    mp.prepare();
                }
                catch( Exception e ) {
                    throw e;
                }

                progressBarLabel.setText("Done - Starting with mapping process");
                // Re-structure the mappings set
                // Note we convert the mappings into an input to output HashMap here
                // because then we do not have to perform a search on each mapping
                /*HashMap<String, ArrayList<String>> tempMappings = new HashMap<String, ArrayList<String>>();
                while (MappingsHandler.self().hasNext()) {
    //            Map.Entry<String, ArrayList> entry = (Map.Entry<String, ArrayList>) mapsIt.next();
                    Map.Entry<String, HashMap<String,MappingRecord>> entry = MappingsHandler.self().next();
                    HashMap<String,MappingRecord> mappingsList = entry.getValue();
                    String outputFieldID = entry.getKey();

                    Iterator<String> mplIt = mappingsList.keySet().iterator();
                    while (mplIt.hasNext()) {
                        String inputFieldID = mplIt.next();
                        ArrayList<String> toMaps = null;

                        if (tempMappings.containsKey(inputFieldID)) {
                            toMaps = tempMappings.get(inputFieldID);
                        } else {
                            toMaps = new ArrayList<String>(0);
                        }
                        toMaps.add(outputFieldID);
                        tempMappings.put(inputFieldID, toMaps);
                    }
                }*/
                progressBar.setValue(25);

                //MappingsHandler.self().printMappings();

                while( mp.processMapping() ) {
                    if( Thread.interrupted() ) {
                        progressBarLabel.setText( "Aborted" );
                        break;
                    }

                    progressBarLabel.setText("Processing Entries - " + mp.getEntriesDone() + " Done.");
                }
            }
            catch( Exception e ) {
                JOptionPane.showMessageDialog( null, "Error Occured during processing: " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE );
                e.printStackTrace();

                progressBarLabel.setText( "Error Occured! Processed entries: " + mp.getEntriesDone() );
            }

            abortButton.setEnabled(false);
            processButton.setEnabled(true);

            /*boolean bDataMapped = false;
            int entriesDone = 0;
            HashMap<String,String> persistentMappings = new HashMap<String,String>();
            while (ifp.hasNext()) {
                // Check if thread got aborted
                if( Thread.interrupted() ) {
                    progressBarLabel.setText( "Aborted" );
                    progressBar.setValue(100);
                    return null;
                }

                DataRecord fr = ifp.next();

                if (fr == null) {
                    ifp.nextEntry();
                    if (bDataMapped) {
                        ofp.nextEntry();
                        bDataMapped = false;
                    }
                    fr = ifp.next();

                    entriesDone++;
                    progressBarLabel.setText("Processing Entries - " + entriesDone + " Done.");
                    persistentMappings = new HashMap<String,String>();
                }

                //System.out.println( "Processing Input: " + fr.getIDRecord() );

                //System.out.println( "InputID: " + fr.getIDRecord() + " Content: " + fr.getRecordContent() );

                // Check if the input ID is mapped
                if (tempMappings.containsKey(fr.getIDRecord())) {
                    ArrayList<String> targets = tempMappings.get(fr.getIDRecord());

                    Iterator<String> tIt = targets.iterator();
                    while (tIt.hasNext()) {
                        boolean bAddNew = false;
                        String currTarget = tIt.next();

                        //System.out.println( "InputID: " + fr.getIDRecord() + " mapped to: " + currTarget );
                        // Get Mapping record for our current mapping
                        MappingRecord cMR = MappingsHandler.self().getMapping(fr.getIDRecord(), currTarget);
                        // Get current datarecord
                        DataRecord cDR = ofp.getDataRecord(currTarget);
                        String recordContent = fr.getRecordContent();

                        // Manipulate record content
                        recordContent = ManipulationsHandler.self().manipulateValue(fr.getIDRecord(), currTarget, recordContent);

                        // Check if existing record is non-empty
                        if( !cDR.getRecordContent().isEmpty() ) {
                            // Now check the action
                            switch (cMR.existsAction) {
                                // Concatenate the contents
                                case CONCATENATE:
                                    recordContent = cDR.getRecordContent() + " " + recordContent;
                                    break;
                                // TODO: Implement COPY action
                                case COPY:
                                    break;
                                // Add a new entry
                                case NEW:
                                    bAddNew = true;
                                    break;
                                // Keep old content
                                case KEEP:
                                    recordContent = cDR.getRecordContent();
                                    break;
                                // Only replace content if the new value is not empty
                                // Which means: keep old content if value is empty
                                case REPLACEIFNOTEMPTY:
                                    if (recordContent.isEmpty()) {
                                        recordContent = cDR.getRecordContent();
                                    }
                                    break;
                                // No additional action required
                                default:
                                    break;
                            }
                        }

                        // Check if this is a persistant mapping
                        if( cMR.persistentMapping ) {
                            persistentMappings.put( currTarget , recordContent );
                        }

                        // Set record content
                        DataRecord ofr = new DataRecord();
                        ofr.setRecordContent(recordContent);
                        ofr.setIDRecord(currTarget);
                        //fr.setRecordContent(recordContent);
                        // Update ID of record
                        //fr.setIDRecord(currTarget);

                        // Write the data record
                        ofp.addDataRecord(ofr, bAddNew, cMR.persistentMapping );

                        // Check if we added a new entry, if yes we have to re-run all persistent mappings
                        if( bAddNew ) {
                            Iterator<String> pmIt = persistentMappings.keySet().iterator();
                            while( pmIt.hasNext() ) {
                                String target = pmIt.next();

                                ofr.setRecordContent( persistentMappings.get( target ) );
                                ofr.setIDRecord(target);

                                ofp.addDataRecord(ofr, false, true);
                            }
                        }

                        bDataMapped = true;
                    }
                }
            }
            progressBar.setValue(90);

            // Finalize the mapping process
            ifp.done();
            ofp.done();*/

            mp.done();

            progressBar.setValue(100);

            return null;
        }
    }

    /** Creates new form ProcessMappingWindow */
    public ProcessMappingWindow() {
        initComponents();

        // Disable the abort button by default
        this.abortButton.setEnabled(false);

        // Add the available file types to the dropdown
        String[] fpTypes = ProcessorHandler.self().getProcessors();
        DefaultComboBoxModel iffCbModel = new DefaultComboBoxModel();
        DefaultComboBoxModel offCbModel = new DefaultComboBoxModel();
        for( int i = 0; i < fpTypes.length; i++ ) {
            iffCbModel.addElement(fpTypes[i]);
            offCbModel.addElement(fpTypes[i]);

            // Get all valid file-types for this handler and add a filenameextensionfilter for it
            String[] fpFileTypes = ProcessorHandler.self().getSupportedFilesForType(fpTypes[i]);
            if( fpFileTypes != null ) {
                String fpFTDescription = fpTypes[i] + " (*." + fpFileTypes[0];
                for( int j = 1; j < fpFileTypes.length; j++ ) {
                    fpFTDescription += ", *." + fpFileTypes[j];
                }
                fpFTDescription += ")";

                //FileNameExtensionFilter filter = new FileNameExtensionFilter( fpFTDescription, fpFileTypes );
                //fc.addChoosableFileFilter(filter);
            }
        }
        this.inputFileFormatComboBox.setModel(iffCbModel);
        this.outputFileFormatComboBox.setModel(offCbModel);

        // Add all available character encodings to the drop-down
        DefaultComboBoxModel ifECbModel = new DefaultComboBoxModel();
        DefaultComboBoxModel ofECbModel = new DefaultComboBoxModel();

        SortedMap<String,Charset> availChars = Charset.availableCharsets();
        Iterator<Map.Entry<String,Charset>> acIt = availChars.entrySet().iterator();
        while( acIt.hasNext() ) {
            Map.Entry<String,Charset> currEntry = acIt.next();

            ifECbModel.addElement(currEntry.getValue());
            ofECbModel.addElement(currEntry.getValue());
        }
        
        this.ifEncodingComboBox.setModel(ifECbModel);
        this.ofEncodingComboBox.setModel(ofECbModel);

        this.mp = new MappingProcess();

        // Create our initial settings windows
        inputFileFormatComboBoxActionPerformed( null );
        outputFileFormatComboBoxActionPerformed( null );
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        progressPanel = new javax.swing.JPanel();
        progressBar = new javax.swing.JProgressBar();
        progressBarLabel = new javax.swing.JLabel();
        abortButton = new javax.swing.JButton();
        processButton = new javax.swing.JButton();
        typeSelectTabbedPanel = new javax.swing.JTabbedPane();
        optionsPanel = new javax.swing.JPanel();
        inputFileFormatLabel = new javax.swing.JLabel();
        outputFileFormatLabel = new javax.swing.JLabel();
        inputFileFormatComboBox = new javax.swing.JComboBox();
        outputFileFormatComboBox = new javax.swing.JComboBox();
        ifEncodingLabel = new javax.swing.JLabel();
        ifEncodingComboBox = new javax.swing.JComboBox();
        ofEncodingLabel = new javax.swing.JLabel();
        ofEncodingComboBox = new javax.swing.JComboBox();
        cfoButton = new javax.swing.JButton();

        setTitle("Process Mapping");
        setResizable(false);

        progressPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Mapping Progress", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 1, 12), new java.awt.Color(1, 1, 1))); // NOI18N

        progressBarLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        progressBarLabel.setText("Progress");

        javax.swing.GroupLayout progressPanelLayout = new javax.swing.GroupLayout(progressPanel);
        progressPanel.setLayout(progressPanelLayout);
        progressPanelLayout.setHorizontalGroup(
            progressPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, progressPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(progressPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(progressBarLabel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 657, Short.MAX_VALUE)
                    .addComponent(progressBar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 657, Short.MAX_VALUE))
                .addContainerGap())
        );
        progressPanelLayout.setVerticalGroup(
            progressPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, progressPanelLayout.createSequentialGroup()
                .addComponent(progressBarLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        abortButton.setText("Abort");
        abortButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                abortButtonActionPerformed(evt);
            }
        });

        processButton.setText("Process");
        processButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                processButtonActionPerformed(evt);
            }
        });

        optionsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Process Options", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 1, 12), new java.awt.Color(1, 1, 1))); // NOI18N

        inputFileFormatLabel.setText("Input Format:");

        outputFileFormatLabel.setText("Output Format:");

        inputFileFormatComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                inputFileFormatComboBoxActionPerformed(evt);
            }
        });

        outputFileFormatComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                outputFileFormatComboBoxActionPerformed(evt);
            }
        });

        ifEncodingLabel.setText("Encoding:");

        ofEncodingLabel.setText("Encoding:");

        cfoButton.setLabel("Change Field Order");
        cfoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cfoButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout optionsPanelLayout = new javax.swing.GroupLayout(optionsPanel);
        optionsPanel.setLayout(optionsPanelLayout);
        optionsPanelLayout.setHorizontalGroup(
            optionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(optionsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(optionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(optionsPanelLayout.createSequentialGroup()
                        .addGroup(optionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(inputFileFormatLabel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(outputFileFormatLabel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(18, 18, 18)
                        .addGroup(optionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(optionsPanelLayout.createSequentialGroup()
                                .addComponent(inputFileFormatComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(ifEncodingLabel))
                            .addGroup(optionsPanelLayout.createSequentialGroup()
                                .addComponent(outputFileFormatComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(ofEncodingLabel)))
                        .addGap(18, 18, 18)
                        .addGroup(optionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(ifEncodingComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(ofEncodingComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(cfoButton))
                .addContainerGap(396, Short.MAX_VALUE))
        );
        optionsPanelLayout.setVerticalGroup(
            optionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(optionsPanelLayout.createSequentialGroup()
                .addGroup(optionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(inputFileFormatLabel)
                    .addComponent(inputFileFormatComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ifEncodingLabel)
                    .addComponent(ifEncodingComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(optionsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(outputFileFormatLabel)
                    .addComponent(outputFileFormatComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ofEncodingLabel)
                    .addComponent(ofEncodingComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(cfoButton)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(optionsPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(typeSelectTabbedPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 691, Short.MAX_VALUE)
                    .addComponent(progressPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(abortButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 541, Short.MAX_VALUE)
                        .addComponent(processButton)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(optionsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(typeSelectTabbedPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 182, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(progressPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(abortButton)
                    .addComponent(processButton))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void processButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_processButtonActionPerformed
        task = new MappingTask();
        task.execute();

        this.processButton.setEnabled(false);
        this.abortButton.setEnabled(true);
    }//GEN-LAST:event_processButtonActionPerformed

    private void abortButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_abortButtonActionPerformed
        //this.setVisible(false);
        if( task != null ) task.cancel(true);

        task = null;

        this.processButton.setEnabled(true);
        this.abortButton.setEnabled(false);
    }//GEN-LAST:event_abortButtonActionPerformed

    private void inputFileFormatComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_inputFileFormatComboBoxActionPerformed
        if( this.inputOptionsPanel != null ) this.typeSelectTabbedPanel.remove( this.inputOptionsPanel );

        // TODO: Replace check with something less static
        if( ((String) this.inputFileFormatComboBox.getSelectedItem()).contains( "JDBC" ) ) {
            this.inputOptionsPanel = new JDBCConnectPanel();
        }
        else {
            this.inputOptionsPanel = new FileSelectPanel();
        }
        this.inputOptionsPanel.setType(true);
        this.inputOptionsPanel.setSourceName((String) this.inputFileFormatComboBox.getSelectedItem());

        this.typeSelectTabbedPanel.insertTab( "Input", null, this.inputOptionsPanel, null, 0 );
        this.typeSelectTabbedPanel.setSelectedIndex( 0 );

        //this.inputTabPanel.add( this.inputOptionsPanel );
        //this.inputTabPanel.validate();
    }//GEN-LAST:event_inputFileFormatComboBoxActionPerformed

    private void outputFileFormatComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_outputFileFormatComboBoxActionPerformed
        if( this.outputOptionsPanel != null ) this.typeSelectTabbedPanel.remove( this.outputOptionsPanel );

        // TODO: Replace check with something less static
        if( ((String) this.outputFileFormatComboBox.getSelectedItem()).contains( "JDBC" ) ) {
            this.outputOptionsPanel = new JDBCConnectPanel();
        }
        else {
            this.outputOptionsPanel = new FileSelectPanel();
        }
        this.outputOptionsPanel.setType(false);
        this.outputOptionsPanel.setSourceName((String) this.outputFileFormatComboBox.getSelectedItem());

        this.typeSelectTabbedPanel.insertTab( "Output", null, this.outputOptionsPanel, null, 1 );
        this.typeSelectTabbedPanel.setSelectedIndex( 1 );

        //this.outputTabPanel.add( this.outputOptionsPanel );
        //this.outputTabPanel.validate();
    }//GEN-LAST:event_outputFileFormatComboBoxActionPerformed

    private void cfoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cfoButtonActionPerformed
        // TODO add your handling code here:
        ChangeFieldOrderWindow.Self().setVisible(true);
    }//GEN-LAST:event_cfoButtonActionPerformed

    @Override
    public void setVisible(boolean b) {
        if( b ) ChangeFieldOrderWindow.Self().Load();

        super.setVisible( b );
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton abortButton;
    private javax.swing.JButton cfoButton;
    private javax.swing.JComboBox ifEncodingComboBox;
    private javax.swing.JLabel ifEncodingLabel;
    private javax.swing.JComboBox inputFileFormatComboBox;
    private javax.swing.JLabel inputFileFormatLabel;
    private javax.swing.JComboBox ofEncodingComboBox;
    private javax.swing.JLabel ofEncodingLabel;
    private javax.swing.JPanel optionsPanel;
    private javax.swing.JComboBox outputFileFormatComboBox;
    private javax.swing.JLabel outputFileFormatLabel;
    private javax.swing.JButton processButton;
    private javax.swing.JProgressBar progressBar;
    private javax.swing.JLabel progressBarLabel;
    private javax.swing.JPanel progressPanel;
    private javax.swing.JTabbedPane typeSelectTabbedPanel;
    // End of variables declaration//GEN-END:variables

}
